package com.dys.teststring09;

import java.util.Arrays;

/**
 * @className: com.dys.teststring09.StringTest2
 * @description: com.dys.teststring09
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/07/29 下午7:54
 */
public class StringTest2 {
    /**
     * 这是一个main()方法,是应用程序的入口
     *
     * @param args 方法的形参列表,是一个字符串数组,包含了从命令行传递给程序的参数
     */
    public static void main(String[] args) {
        new StringTest2().testStrMethod();
    }

    public void testStrMethod() {
        // 字符串截取
        String s1 = "abcdefghijklmnopqrst";
        String substring = s1.substring(2);
        System.out.println(substring);
        // [2,3)
        String substring1 = s1.substring(2, 5);
        System.out.println(substring1);
        // 字符串拼接
        String s2 = "abcdefghijklmnopqrst";
        String abcdefghijklmnopqrst = s2.concat("ABCDEFGHIJKLMNOPQRST");
        System.out.println(abcdefghijklmnopqrst);

        // 字符串替换: 需要替换的字符替换为指定支付
        String s3 = "abcdefgabeabc";
        String replace = s3.replace('a', 'A');
        System.out.println(replace);

        // 字符串分割
        String s4 = "a-b-c-d-e-f-g-h-i-j-klmnopqrst";
        String[] split = s4.split("-");
        System.out.println(Arrays.toString(split));

        // 转大写
        String s5 = "abcdefghijklmnopqrst";
        String upperCase = s5.toUpperCase();
        System.out.println("转大写: " + upperCase);
        String s6 = "ABCDEFGHIJKLMNOPQRST";
        String lowerCase = s6.toLowerCase();
        System.out.println("转小写: " + lowerCase);

        // 去除首尾空格
        String s7 = "    a  b  c    defghijklmnopqrst    ";
        String trim = s7.trim();
        System.out.println(trim);

        String s8 = "abcdefghijklmnopqrst";
        System.out.println(s8.toString());

        // 将其它数据类型转为字符串类型
        String sInt = String.valueOf(1);
        System.out.println(sInt);
        String sBool = String.valueOf(true);
        System.out.println(sBool);
    }
}
